package calendar;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * CalendarMgrType.
 *
 * @author  James H. Pope
 * @version $Revision:$ $Date:$
 */
public class Type //implements Serializable
{   
    /**
     * List of Types
     */
    public static final List<Type> TYPES = new ArrayList<Type>();
    
    /**
     * Primary CalendarMgr.
     */
    public static final Type PRIMARY = new Type( 1, "Primary" );

    /**
     * Replica CalendarMgr.
     */
    public static final Type BACKUP = new Type( 2, "Backup" );
    
    
    //------------------------------------------------------------------------//
    
    /**
     * id
     */
    private int id = 0;
    
    /**
     * name
     */
    private String name = null;
    
    
    
    /**
     * Creates a new EndianFlag with specified values.
     * @param id
     * @param name
     */
    public Type( int id , String name )
    {
        this.id     = id;
        this.name   = name;
        
        TYPES.add(this);
    }
    
    /**
     * Gets id.
     * @return id
     */
    public int getId()
    {
        return this.id;
    }
    
    /**
     * Gets name.
     * @return name
     */
    public String getName()
    {
        return this.name;
    }
     
    /**
     * Gets enum from given id
     * @param id of enum to get
     * @return enum of given id or null if not found
     */
    public static Type get( int id )
    {
        Type e = null;
        for (int i = 0; i < TYPES.size(); i++)
        {
            Type t = TYPES.get(i);
            if( t.getId() == id )
            {
                e = t;
            }
        }
        return e;
    }
    
    /**
     * Gets enum from given name (assumes names are unique, returns first occ).
     * The name is non-case sensitive.
     * @param name of enum to get
     * @return enum of given name or null if not found
     */
    public static Type get( String name )
    {
        Type e = null;
        for (int i = 0; i < TYPES.size(); i++)
        {
            Type t = TYPES.get(i);
            if( t.getName().equalsIgnoreCase(name) )
            {
                e = t;
            }
        }
        return e;
    }
     
     
    /**
     * Gets this String facsimile of this object.
     * @return name
     */
    public String toString( )
    {
        return this.name;
    }
}
